package com.h2View.entity;

import cn.hutool.log.Log;
import cn.hutool.log.LogFactory;

import java.util.ArrayList;
import java.util.List;

/**
 * @author xwx1052336
 * @since 2021/9/17
 */
public enum DataType {

    H2(1,"h2","8082","org.h2.Driver"),
    POSTGRESQL(2,"PostgreSQL","5432","org.postgresql.Driver");

    private Integer dataType;
    private String dataMsg;
    private String dataPort;
    private String driver;
    private static Log log = LogFactory.get();

    private static List<String> dataMsgs;

    DataType(Integer dataType,String dataMsg,String dataPort,String driver){
        this.dataMsg = dataMsg;
        this.dataType = dataType;
        this.dataPort = dataPort;
        this.driver = driver;
    }

    public static List<String> getAllDataMsg(){
        if( dataMsgs == null ){
            dataMsgs = new ArrayList<>(DataType.values().length);
            for(DataType dataType:DataType.values()){
                dataMsgs.add(dataType.getDataMsg());
            }
        }
        log.info("未找到数据库，使用默认数据库");
        return dataMsgs;
    }

    public static DataType getDataType(String dataMsg){
        for(DataType dataType:DataType.values()){
            if(dataType.getDataMsg().equals(dataMsg)){
                return dataType;
            }
        }

        return null;
    }

    public Integer getDataType() {
        return dataType;
    }

    public void setDataType(Integer dataType) {
        this.dataType = dataType;
    }

    public String getDataMsg() {
        return dataMsg;
    }

    public void setDataMsg(String dataMsg) {
        this.dataMsg = dataMsg;
    }

    public String getDataPort() {
        return dataPort;
    }

    public void setDataPort(String dataPort) {
        this.dataPort = dataPort;
    }

    public String getDriver() {
        return driver;
    }

    public void setDriver(String driver) {
        this.driver = driver;
    }
}
